package com.nulldev.util.internal.backport.httpclient_rw.impl.common;

import java.util.ResourceBundle;

public class LoggerCompatLayer {

	public static ILogger getLogger(String name) {
		return new CompatLogger(name);
	}

	public static class CompatLogger extends com.nulldev.util.logging.Logger implements ILogger {

		private final String className;

		public CompatLogger(final String className) {
			super(className);
			this.className = className;
		}

		@Override
		public String getName() {
			return this.className;
		}

		@Override
		public boolean isLoggable(com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level level) {
			if (level == com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level.OFF)
				return this.isLoggingEnabled();
			else if (level == com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level.DEBUG)
				return this.debugEnabled.get();
			else if (level == com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level.INFO)
				return this.infoEnabled.get();
			else if (level == com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level.ERROR)
				return this.errorEnabled.get();
			else if (level == com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level.TRACE)
				return this.traceEnabled.get();
			else if (level == com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level.WARNING)
				return this.warnEnabled.get();
			else if (level == com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level.ALL)
				return this.infoEnabled.get() && this.debugEnabled.get();
			else
				return false;
		}

		@Override
		public void log(com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level level, ResourceBundle bundle, String msg, Throwable thrown) {
			switch (level) {
				case ERROR: {
					this.error(msg, thrown);
					break;
				}
				default:
					throw new UnsupportedOperationException("Unknown level: " + level);
			}
		}

		@Override
		public void log(com.nulldev.util.internal.backport.httpclient_rw.impl.common.ILogger.Level level, ResourceBundle bundle, String format,
				Object... params) {
			switch (level) {
				case ERROR: {
					this.error(format, params);
					break;
				}
				case INFO: {
					this.info(format, params);
					break;
				}
				case WARNING: {
					this.warn(format, params);
					break;
				}
				case ALL: {
					this.info(format, params);
					break;
				}
				case DEBUG: {
					this.debug(format, params);
					break;
				}
				case TRACE: {
					this.trace(format, params);
					break;
				}
				default:
					throw new UnsupportedOperationException("Unknown level: " + level);
			}
		}

	}

}
